package cc.mrbird.febs.music.controller;

import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.domain.QueryRequest;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.music.domain.MusicBean;
import cc.mrbird.febs.music.domain.MusicMoodBean;
import cc.mrbird.febs.music.domain.MusicToUser;
import cc.mrbird.febs.music.service.MusicMoodService;
import cc.mrbird.febs.music.service.MusicService;
import cc.mrbird.febs.system.domain.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@Slf4j
@Validated
@RestController
@RequestMapping("music")
@Api(value = "网易音乐列表")
public class MusicController extends BaseController {

    private String message;

    @Autowired
    private MusicService dataAllService;
    @Autowired
    private MusicMoodService musicMoodService;

    @GetMapping("/list")
    @ApiOperation(value = "网易音乐列表")
    public Map<String, Object> getData(QueryRequest queryRequest, MusicBean musicBean, MusicMoodBean musicMoodBean) {
        log.info("param name ={}", musicBean);
        musicBean.setMusicMoodBean(musicMoodBean);
        return getDataTable(dataAllService.getData(musicBean, queryRequest));
    }

    @PostMapping("update")
    @ApiOperation(value = "更新用户偏爱")
    public void updateUser(@Valid MusicMoodBean musicMoodBean) throws FebsException {
        try {
            this.musicMoodService.updateMusicMood(musicMoodBean);
        } catch (Exception e) {
            message = "修改失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }

    @GetMapping("listUser")
    public List<MusicToUser> listUser (String musicId) {
        return this.dataAllService.listUser(musicId);
    }

    @GetMapping("listMusicByUser")
    List<MusicBean> listMusicByUser(String userId){
        return this.dataAllService.listMusicByUser(userId);
    }
}
